package A_review.review1_15;

import A_review.review9_4.QuickSortt;

public class QuickSort {

    public   void  quickSort(int[] nums){
        if (nums.length==0){
            return;
        }
        sort(nums,0,nums.length-1);
    }

    public  void  sort(int[] nums,int lo,int hi){
        if (lo>=hi){
            return;
        }
        int part = find(nums, lo, hi);
        sort(nums,lo,part-1);
        sort(nums,part+1,hi);
    }

    public  int  find(int[] nums,int lo,int hi){
        int stand=nums[lo];
        int j=lo+1;
        int k=hi;
        while (j<=k){
             while (j<=hi&&nums[j]<=stand){
                 j++;
             }
             while (k>=lo&&nums[k]>stand){
                 k--;
             }

             if (j>k){
                 break;
             }
             swap(nums,j,k);
        }
        swap(nums,lo,k);
        return  k;
    }

    public  void  swap(int[] nums,int j,int k){
        int temp = nums[j];
        nums[j]=nums[k];
        nums[k]=temp;
    }

    public static void main(String[] args) {
        QuickSort quickSort = new QuickSort();
        int[] cur={4,52,61,12,5,53};
        quickSort.quickSort(cur);
        for (int a:cur
             ) {
            System.out.println(a);

        }

    }



}
